package logic

import (
	"context"

	"go-zero-demo-04/mall/result/api/internal/svc"
	"go-zero-demo-04/mall/result/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetclassLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetclassLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetclassLogic {
	return &GetclassLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetclassLogic) Getclass(req *types.GetclassRequest) (resp *types.GetrclassListResponse, err error) {

	list, err := l.svcCtx.ResultModel.FindClass(l.ctx, req.ClassID)
	if err != err {
		return nil, err
	}

	var res []types.GetclassResponse

	for _, item := range list {
		var temp types.GetclassResponse
		temp.StudentID = item.StudentNo
		temp.MBTIcode = item.MbitCode
		temp.Time = item.TestTime
		temp.ClassID = item.StudnetClass
		res = append(res, temp)
	}
	return &types.GetrclassListResponse{ClassList: res}, nil
}
